#coding=utf8
# Create your views here.
from google.appengine.ext.db import GqlQuery
from django.http import HttpResponse
from django.shortcuts import render_to_response
from pyamf.remoting.gateway.django import DjangoGateway
from linllx.web.models import Memo
from datetime import datetime,timedelta
def index(request):

    return render_to_response('index.html',{})
def addMemo(request,data):
   # print 'hello'
    mydate = datetime.utcnow() + timedelta(hours=+8)
    memo=Memo(author=data['author'],content=data['content'],datetime=mydate)
    memo.put()
    return 'success'#u'留言发表成功'
def getAll(request):
    #query=Memo.all()
    #query.order(datetime)
    try:
        query=GqlQuery("SELECT * FROM Memo ORDER BY datetime DESC LIMIT 18")
        result=[]
        result=map(make,query)
    #result.reverse()
        return result
    except Exception,e:
        return e.message
    return 'success'
def make(memo):
    datetime=memo.datetime.strftime("%Y-%m-%d %H:%M %z")
    temp=u'%s 在 %s 发表了：%s'%(memo.author,datetime,memo.content)

    return temp
services = {
    'addMemo':addMemo,
    'getAll':getAll,
    # could include other functions as well
}

gw = DjangoGateway(services)
